<?php
/*sink_cup
2009-4-19 19:46:44 UTC+8
*/
$nickname=$_POST['nickname'];
$password=$_POST['password'];
$password_confirm=$_POST['password_confirm'];
$email=$_POST['email'];
include '../config.php';
$pvpgn_bnet=$prefix.'bnet';
$pvpgn_record=$prefix.'record';

if(empty($nickname)||empty($password)||empty($password_confirm)||empty($email))
	{
		header("Location: ../register.php?e=0");
		exit();
	}
//检查昵称的字符
$name_allowed_chars='0123456789abcdefghijklmnopqrstuvwxyz_';
$length1=strlen($nickname);
for($i=0;$i<$length1;$i++)
{
	$one_char=substr($nickname,$i,1);
	if(!stripos($name_allowed_chars,$one_char,0))
	{
		header("Location: ../register.php?e=1");
		exit();
	}
}
//检查昵称是否已被注册
$result=$conn->query("SELECT uid FROM $pvpgn_bnet WHERE acct_username='$nickname'");
if($result->num_rows!=0)
{
	$result->free();
	$conn->close();
	header("Location: ../register.php?e=2");
	exit();
}
//检查邮箱的字符
$email_allowed_chars='0123456789abcdefghijklmnopqrstuvwxyz_@.';
$length2=strlen($email);
if(!stripos($email,'@',0)||!stripos($email,'.',0))
{
	header("Location: ../register.php?e=3");
	exit();
}
for($i=0;$i<$length2;$i++)
{
	$one_char=substr($email,$i,1);
	if(!stripos($email_allowed_chars,$one_char,0))
	{
		header("Location: ../register.php?e=3");
		exit();
	}
}
//检查邮箱是否已被注册
$result=$conn->query("SELECT uid FROM $pvpgn_bnet WHERE acct_email='$email'");
if($result->num_rows!=0)
{
	$result->free();
	$conn->close();
	header("Location: ../register.php?e=4");
	exit();
}
//检查密码长度必须大于3
if(strlen($password)<3)
{
	header("Location: ../register.php?e=5");
	exit();
}
//检查两次密码是否一致
if($password!=$password_confirm)
{
	header("Location: ../register.php?e=6");
	exit();
}
//对密码进行加密
include './pvpgn_hash.php';
$passhash = pvpgn_hash($password);
//生成uid编号
$result=$conn->query("SELECT MAX(uid) FROM $pvpgn_bnet");
if($rows=$result->fetch_row())
{
	$uid=$rows[0]+1;
}
//插入数据库新用户注册资料
$result=$conn->query("INSERT INTO $pvpgn_bnet (uid,acct_username,username,acct_userid,acct_passhash1,acct_email) VALUES('$uid','$nickname','$nickname','$uid','$passhash','$email')");
//插入数据库新用户战绩（为了1级即可以使用所有头像）
$result=$conn->query("INSERT INTO $pvpgn_record (uid,WAR3_solo_level,W3XP_solo_level) VALUES('$uid','1','1')");
if($result==1)
{
	$conn->close();
	header("Location: ../player.php?PlayerName=$nickname");
	exit();
}
?>